package com.woniu.humanresource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.humanresource.entity.Accets;
import com.woniu.humanresource.entity.Purchase;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PurchaseController {
    @Autowired
    PurchaseService purchaseService;
    //分页条件查询
    @PostMapping("/getAllPurchasePageBean/{pageIndex}/{pageSize}")
    public ResponseText<Page<Purchase>> getAllPurchasePageBean(@PathVariable("pageIndex") int pageIndex,
                                                           @PathVariable("pageSize") int pageSize,
                                                           @RequestBody Purchase purchase){
        System.out.println("■■■■■■查询■■■■■■"+purchase);

        Page<Purchase> purchases = purchaseService.getPurchases(pageIndex, pageSize, purchase);

        ResponseText<Page<Purchase>> responseText=new ResponseText<>(purchases, 200, "OK");
        return responseText;
    }

    //根据id查询
    @PostMapping("/getPurchaseById/{purchaseid}")
    public ResponseText<Purchase> getPurchaseById(@PathVariable("purchaseid") int purchaseid){
        System.out.println("■■■■■■查询■■■■■■"+purchaseid);

        Purchase purchase = purchaseService.getPurchaseById(purchaseid);

        ResponseText<Purchase> responseText=new ResponseText<>(purchase, 200, "OK");
        return responseText;
    }

    //单个作废
    @DeleteMapping("/removePurchaseById/{purchaseId}")
    public ResponseText<Page<Purchase>> removePurchaseById(@PathVariable("purchaseId") int purchaseId){
        System.out.println("■■■■■■单个删除■■■■■■"+purchaseId);

        purchaseService.removePurchaseById(purchaseId);

        ResponseText<Page<Purchase>> responseText=new ResponseText<>(null, 200, "OK");
        return responseText;
    }

    //批量作废
    @DeleteMapping("/purchases")
    public ResponseText<Page<Purchase>> removeMultiplePurchasesById(@RequestBody List<Purchase> purchases){
        System.out.println("■■■■■■批量删除■■■■■■"+"【参数长度:"+purchases.size()+"】具体参数:"+purchases);

        purchaseService.removeMultiplePurchasesById(purchases);

        ResponseText<Page<Purchase>> responseText=new ResponseText<>(null, 200, "OK");
        return responseText;
    }


    //添加采购表
    @PostMapping("/addPurchase")
    public ResponseText<Integer> addWarehouse(@RequestBody Purchase purchase){
        System.out.println("■■■■■■添加■■■■■■"+purchase);

        Integer id = purchaseService.addPurchase(purchase);//调service方法去插入
        System.out.println(id);

        ResponseText<Integer> responseText=new ResponseText<>(id, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

}
